package com.yihen.config;

import com.yihen.service.impl.IUserService;
import com.yihen.util.LoginInterceptor;
import com.yihen.util.RefreshTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Resource
    private IUserService userService;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 登录拦截器
        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(
//                "/goods/select/**",
//                "/goods/hotgoods",
//                "/goods/detail/**",
//                "/users/login",
//                "/users/register",
//                "/goods/classify/**",
//                "/goods/price/**",
//                "/verify/code",
//                "/users/verify"
                    "/**"

                ).order(1);
        // 刷新拦截器
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate,userService)).addPathPatterns("/**").order(0);
    }
}

